package com.cskaoyan.market.controller.wx;

import com.cskaoyan.market.db.domain.MarketGoods;
import com.cskaoyan.market.db.domain.MarketTopic;
import com.cskaoyan.market.service.wx.WxTopicService;
import com.cskaoyan.market.util.ResponseUtil;
import com.cskaoyan.market.util.VoUtil;
import com.cskaoyan.market.vo.wx.HotGoodsVo;
import com.cskaoyan.market.vo.wx.TopicRelatedVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * @ClassName: TopicController
 * @Auther: lyz
 * @Date: 2023/05/20/22:32
 * @Description:
 */
@RestController
@RequestMapping("wx/topic/")
public class WxTopicController {
    @Autowired
    WxTopicService topicService;

    @GetMapping("list")
    public Object topicList(Integer page, Integer limit) {
        List<MarketTopic> marketTopicList = topicService.list(page, limit);
//        HashMap<String, Object> map = new HashMap<>();
//        map.put("limit", limit);
//        map.put("list", VoUtil.objectToVolist(marketTopicList, TopicVo.class));
//        map.put("page", page);
//        map.put("pages", marketTopicList.size() / limit);
//        map.put("total", marketTopicList.size());
        Object o = ResponseUtil.okList(marketTopicList);
        return o;
    }

    @GetMapping("detail")
    public Object topicDetail(Integer id) {
        MarketTopic topic = topicService.detailTopic(id);
        List<MarketGoods> good = topicService.detailGoods(id);
        HashMap<Object, Object> map = new HashMap<>();
        map.put("topic", VoUtil.objectVo(topic, TopicRelatedVo.class));
        map.put("goods", VoUtil.objectToVolist(good, HotGoodsVo.class));
        Object o = ResponseUtil.ok(map);
        //TODO goods[]待优化
        return o;
    }

    @GetMapping("related")
    public Object topicRelated(Integer id) {
        List<MarketTopic> related = topicService.related(id);
//        HashMap<String, Object> map = new HashMap<>();
//        map.put("limit", 4);
//        map.put("list", VoUtil.objectToVolist(related, TopicRelatedVo.class));
//        map.put("page", 1);
//        map.put("pages", 6);
//        map.put("total", 21);
        //TODO 返回参数待动态化
        return ResponseUtil.okList(related);
    }
//    public Object topicRelated(Integer id) {
//        HashMap<String, Object> related = topicService.related(id);
//        HashMap<String, Object> map = new HashMap<>();
//        return ResponseUtil.ok(map);
//    }
}
